<template>
  <div>
    <el-menu
        :default-active="this.$store.state.menus.editableTabsValue"
        class="el-menu-vertical-demo"

        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b">
      <router-link to="/index">

        <el-menu-item index="Index" @click="selectMenu({name: 'Index', title: '首页'})">
          <template #title>
            <el-icon><HomeFilled /></el-icon>
            <span>首页</span>
          </template>
        </el-menu-item>


      </router-link>

      <el-sub-menu :index="menu.name" v-for="(menu, index) in menuList" :key="index"
                   text-color="#fff"
                   active-text-color="#ffd04b">
        <template #title>
          <el-icon><Histogram /></el-icon>
          <span>{{menu.title}}</span>
        </template>
        <router-link :to="item.path" v-for="(item, subIndex) in menu.children" :key="subIndex">
          <el-menu-item :index="item.name" @click="selectMenu(item)">
            <template #title>
              <el-icon><Notebook /></el-icon>
              <span>{{item.title}}</span>
            </template>
          </el-menu-item>
        </router-link>

      </el-sub-menu>
    </el-menu>
  </div>

</template>

<script>
export default {
  name: "SideMenu",
  data() {
    return {

    }
  },
  computed: {
    menuList: {
      get() {
        console.log("$store.state.menus.menuList = ", this.$store.state.menus.menuList)
        return this.$store.state.menus.menuList
      }
    }
  },
  created() {
    console.log("menuList = ", this.menuList)
  },
  methods: {
    selectMenu(item) {
      console.log("item:", item);
      this.$store.commit("addTab", item);
    }
  }
}
</script>

<style scoped>
.el-menu-vertical-demo {
  height: 100%;
  text-align: left;
}
a {
  text-decoration: none;
}
</style>